home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WhackABill.sit / Whack-A-Bill / source code / async.h < prev    next >
Text File  |  1997-09-24  |  1KB  |  99 lines

  1. void PlayAsync(int drawState);
  2. void SetupSound(void);
  3. void DisposeSound(void);
  4.  
  5. SndChannelPtr channelArray[10];
  6. Handle soundOne;
  7. Handle soundTwo;
  8. int lastSoundPlayed;
  9.  
  10. void PlayAsync(int drawState)
  11. {
  12. int foundChan=0;
  13. Boolean chanSet=false;
  14. int openChan = 0;
  15. SCStatus chanStatus;
  16. OSErr err;
  17. Handle theSound;
  18.  
  19. if (!(drawState==lastSoundPlayed))
  20. {
  21. switch (drawState)
  22. {
  23. case 1:
  24. theSound=soundOne;
  25. lastSoundPlayed = 1;
  26. break;
  27. case 2:
  28. theSound=soundTwo;
  29. lastSoundPlayed = 2;
  30. break;
  31. case 3:
  32. theSound=soundOne;
  33. lastSoundPlayed = 3;
  34. break;
  35. case 4:
  36. lastSoundPlayed = 4;
  37. break;
  38. case 5:
  39. lastSoundPlayed = 5;
  40. theSound=soundTwo;
  41. break;
  42. case 6:
  43. lastSoundPlayed = 6;
  44. theSound=soundTwo;
  45. break;
  46. case 7:
  47. lastSoundPlayed = 7;
  48. theSound=soundTwo;
  49. break;
  50. case 8:
  51. lastSoundPlayed = 8;
  52. theSound=soundTwo;
  53. break;
  54. }
  55.  
  56.             while (chanSet==false)
  57.             {
  58.             SndChannelStatus(channelArray[openChan],sizeof(chanStatus),&chanStatus);
  59.                 if(!(chanStatus.scChannelBusy))
  60.                 {
  61.                 chanSet=true;
  62.                 }
  63.             else openChan++;
  64.             if (openChan>9)
  65.             chanSet=true;
  66.             }
  67.  
  68.         if(!(openChan>9))
  69.         {
  70.         SndPlay(channelArray[openChan],(SndListHandle)theSound,true);
  71.         }
  72.     }
  73. }
  74.  
  75. void SetupSound(void)
  76. {
  77. int i;
  78.  
  79.     for (i=0;i<10;i++)
  80.     {
  81.         channelArray[i] = nil;
  82.         SndNewChannel(&channelArray[i],sampledSynth,0,nil);
  83.     }
  84.     
  85. soundOne=GetResource('snd ',400);
  86. soundTwo=GetResource('snd ',401);
  87. }
  88.  
  89. void DisposeSound(void)
  90. {
  91. int i;
  92.  
  93. for (i=0;i<10;i++)
  94.     {
  95.     
  96.     SndDisposeChannel(channelArray[i],true);
  97.     
  98.     }
  99. }